package com.hr.剑指offer.work1;

/**
 * @author 周恒哲
 * @date 2020/06/16
 **/
public class 面试题15_二进制中1的个数 {
    public static int hammingWeight(int n) {
        int count=0;
        while(n!=0){
            count++;
            n=n&(n-1);
        }
        return count;
    }
    public static int hammingWeight2(int n) {
        int count=0;
        while(n!=0){
            count +=n&1;
            n >>>= 1;
        }
        return count;
    }

    public static void main(String[] args) {
        System.out.println(面试题15_二进制中1的个数.hammingWeight(00000000000000000000000000001011));
    }
}
